﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.FactoryManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.FactoryManagement.EncodeItemVMs
{
    public partial class EncodeItemListVM : BasePagedListVM<EncodeItem_View, EncodeItemSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EncodeItem_View>> InitGridHeader()
        {
            return new List<GridColumn<EncodeItem_View>>{
                
                this.MakeGridHeader(x => x.EncodeItem_Scheme).SetTitle(@Localizer["Page.方案"].Value),
                this.MakeGridHeader(x => x.EncodeItem_ValueName).SetTitle(@Localizer["Page.值名称"].Value),
                this.MakeGridHeader(x => x.EncodeItem_ValueMode).SetTitle(@Localizer["Page.值类型"].Value),
                this.MakeGridHeader(x => x.EncodeItem_Value).SetTitle(@Localizer["Page.值"].Value),
                this.MakeGridHeader(x => x.EncodeItem_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.EncodeItem_Pos).SetTitle(@Localizer["_Admin.DisplayOrder"].Value),
                this.MakeGridHeader(x => x.EncodeItem_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EncodeItem_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EncodeItem_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EncodeItem_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EncodeItem_View> GetSearchQuery()
        {
            var query = DC.Set<EncodeItem>()
                
                .CheckEqual(Searcher.SchemeId, x=>x.SchemeId)
                .CheckContain(Searcher.ValueName, x=>x.ValueName)
                .CheckEqual(Searcher.ValueMode, x=>x.ValueMode)
                .CheckContain(Searcher.Value, x=>x.Value)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckEqual(Searcher.Pos, x=>x.Pos)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EncodeItem_View
                {
				    ID = x.ID,
                    
                    EncodeItem_Scheme = x.Scheme.TenantCode,
                    EncodeItem_ValueName = x.ValueName,
                    EncodeItem_ValueMode = x.ValueMode,
                    EncodeItem_Value = x.Value,
                    EncodeItem_Remark = x.Remark,
                    EncodeItem_Pos = x.Pos,
                    EncodeItem_CreateTime = x.CreateTime,
                    EncodeItem_UpdateTime = x.UpdateTime,
                    EncodeItem_CreateBy = x.CreateBy,
                    EncodeItem_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EncodeItem_View: EncodeItem
    {
        
        public string EncodeItem_Scheme { get; set; }
        public string EncodeItem_ValueName { get; set; }
        public ValueTypeEnum? EncodeItem_ValueMode { get; set; }
        public string EncodeItem_Value { get; set; }
        public string EncodeItem_Remark { get; set; }
        public int? EncodeItem_Pos { get; set; }
        public DateTime? EncodeItem_CreateTime { get; set; }
        public DateTime? EncodeItem_UpdateTime { get; set; }
        public string EncodeItem_CreateBy { get; set; }
        public string EncodeItem_UpdateBy { get; set; }

    }

}